package com.zbl.zblproject.erp.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zbl.zblproject.erp.entity.ErpInventoryOrder;
import com.zbl.zblproject.erp.entity.ErpOrderItem;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.math.BigInteger;
import java.util.List;

/**
 * @author youlanqiang
 * @version 1.0
 * @date 2018/10/19
 */
@Repository
public interface ErpInventoryOrderMapper extends BaseMapper<ErpInventoryOrder> {

    @Select("select * from zbl_inventory_order where inventory_sn=#{inSn} limit 0,1")
    ErpInventoryOrder selectByInSn(@Param("inSn")String inSn);

    @Select("select a.create_time,a.inventory_sn as orderSn,b.inventory_num as goodsNum,a.`mode` from zbl_inventory_order a LEFT JOIN zbl_inventory_orderitem b on a.id=b.order_id where a.mode=2  and b.goods_id=#{goodsId} and a.status=2 order by a.create_time DESC")
    List<ErpOrderItem> selectLy(@Param("goodsId")int goodsId);

    @Select("select a.create_time,a.inventory_sn as orderSn,b.inventory_num as goodsNum,a.`mode` from zbl_inventory_order a LEFT JOIN zbl_inventory_orderitem b on a.id=b.order_id where a.mode=3  and b.goods_id=#{goodsId} and a.status=2 order by a.create_time DESC")
    List<ErpOrderItem> selectTh(@Param("goodsId")int goodsId);

    @Select("select a.create_time,a.inventory_sn as orderSn,b.inventory_num as goodsNum,a.`mode` from zbl_inventory_order a LEFT JOIN zbl_inventory_orderitem b on a.id=b.order_id where a.mode=0  and b.goods_id=#{goodsId} and a.status=2 order by a.create_time DESC")
    List<ErpOrderItem> selectPd(@Param("goodsId")int goodsId);

    @Select("select a.create_time,a.inventory_sn as orderSn,b.inventory_num as goodsNum,a.`mode` from zbl_inventory_order a LEFT JOIN zbl_inventory_orderitem b on a.id=b.order_id where a.mode=1  and b.goods_id=#{goodsId} and a.status=2 order by a.create_time DESC")
    List<ErpOrderItem> selectBs(@Param("goodsId")int goodsId);

    @Update("update zbl_inventory_order set status=#{status} where inventory_sn=#{orderSn}")
    int updateOrderConfirm(@Param("orderSn")String orderSn,@Param("status")int status);

}
